package com.example.project_out_in;

import Business.bSQL_Heper;
import Entities.ECustomer_;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class Register_CustomerActivity extends Activity {
	EditText txtFullname;
	Spinner  spinner;
	EditText txtBirthday;
	EditText txtCMND;
	EditText txtNguyenQuan;
	EditText txtAddress;
	Button   btnCapnhat;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Set View to register.xml
		setContentView(R.layout.register_customer);

		spinner = (Spinner)findViewById(R.id.planets_spinner);
		// Create an ArrayAdapter using the string array and a default spinner layout
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
				R.array.sex_array, android.R.layout.simple_spinner_item);
		// Specify the layout to use when the list of choices appears
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// Apply the adapter to the spinner
		spinner.setAdapter(adapter);

		spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub

			}
		});
		TextView loginScreen = (TextView) findViewById(R.id.link_to_login);

		// Listening to Login Screen link
		loginScreen.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				// Switching to Login Screen/closing register screen
				finish();
			}
		});
		txtFullname = (EditText)findViewById(R.id.reg_fullname);
		// spinner=(Spinner)findViewById(R.id.planets_spinner);
		txtAddress=(EditText)findViewById(R.id.reg_address);
		txtBirthday=(EditText)findViewById(R.id.reg_password);
		txtCMND=(EditText)findViewById(R.id.reg_CMND);
		txtNguyenQuan=(EditText)findViewById(R.id.reg_email);
		btnCapnhat = (Button) findViewById(R.id.btnRegister);
		btnCapnhat.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				bSQL_Heper b = new bSQL_Heper(getBaseContext());
				ECustomer_ c = new ECustomer_();
				c.setFullname(txtFullname.getText().toString());
				c.setSex(spinner.getSelectedItem().toString());
				c.setBirthday(txtBirthday.getText().toString());
				c.setCMND(txtCMND.getText().toString());
				c.setBorn(txtNguyenQuan.getText().toString());
				c.setAddress(txtAddress.getText().toString());
				//Log.d("helo", txtFullname.getText().toString()+" goi tinh "+txtSex.getSelectedItem().toString()+"  ngay sinh "+txtBirthday.getText().toString());
				b.addCustomer_(c);
				//Log.d("helo", "Da tao thanh cong");
			}
		});

	}
}